package lenfs.util;

public class Export {

	private String filePath;
	private String fileSystemPath;
	private String network;
	private String networkMask;

	private boolean readOnly;
	private boolean bits32;
	private boolean allDirectories;

	private int hash;

	public Export(String filePath) {
		this(filePath, false, true, false, null, null, null);
	}

	public Export(final String filePath, boolean readOnly) {
		this(filePath, readOnly, true, false, null, null, null);
	}

	private void addToHash(String s, String hash) {
		if (s != null)
			hash += s;
	}

	private void addToHash(boolean b, String hash) {
		if (b)
			hash += "1";
		else
			hash += "0";
	}

	public Export(String filePath, boolean readOnly, boolean bits32,
			boolean allDirectories, String fsPath, String network,
			String networkMask) {
		this.filePath = filePath;
		this.readOnly = readOnly;
		this.bits32 = bits32;
		this.allDirectories = allDirectories;
		this.fileSystemPath = fsPath;
		this.network = network;
		this.networkMask = networkMask;

		String pathFileLocal = "";
		if (filePath != null)
			pathFileLocal += filePath;

		addToHash(this.filePath, pathFileLocal);
		addToHash(this.readOnly, pathFileLocal);
		addToHash(this.bits32, pathFileLocal);
		addToHash(this.allDirectories, pathFileLocal);
		addToHash(this.fileSystemPath, pathFileLocal);
		addToHash(this.network, pathFileLocal);
		addToHash(this.networkMask, pathFileLocal);

		this.hash = pathFileLocal.hashCode();
	}

	public String getPath() {
		return filePath;
	}

	public boolean isReadOnly() {
		return readOnly;
	}

	public boolean isBits32() {
		return bits32;
	}

	public boolean canMountAllDirectories() {
		return allDirectories;
	}

	public String getFileSystemPath() {
		return fileSystemPath;
	}

	public String getNetwork() {
		return network;
	}

	public String getMask() {
		return networkMask;
	}

	public int hashCode() {
		return hash;
	}

	public boolean equals(Object o) {
		if (o == null)
			return false;
		return hash == o.hashCode();
	}

	public boolean packetFromPath(String filePath, XDR xdrPacket) {
		if (filePath == null)
			return false;
		return filePath.equals(this.filePath);
	}
}
